<template>
	<view>
		<!-- 头部导航 -->
		<page-header :headInfo="headInfo"></page-header>
		<view class="upload-btn">
			<button class="cu-btn cuIcon bg-blue" @tap="goUpload">
				<text class="cuIcon-cameraadd"></text>
			</button>
			<view>我也要传</view>
		</view>
		<view>
			<scroll-view class="atlas-list" :id="scrollId" :scroll-y="isScroll" @scroll="scroll" @scrolltolower="scrolltolower" v-if="uploadsList.length > 0">
				<view v-for="item in uploadsList" class="atlas-image">
					<lazy-load
							:key="imgPath + item.imgUrl"
							:src="imgPath + item.imgUrl"
							:content="content"
							:atlasId="item.id"
							:scroll-id="'#'+scrollId"
							@controlRoll="controlRoll"
							@refresh="refresh"
							mode="aspectFill"></lazy-load>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import lazyLoad from '../../components/lazyLoad/index';
	import lazyLoadPlugin from '../../plugins/lazyLoad/js/index';
	export default {
		data() {
			return {
				scrollId: "scroll",
				imgPath:this.imgPath,
				headInfo:{
					title:'我的上传',
				},
				uploadsList:[],
				pages:0,
				isScroll:true,
				content:[
					{
						text:'反馈',
						status:1
					}
				]
			}
		},
		onShow() {
			this.uploadList();
		},
		/**
		 * @author smallfour
		 * @description 分享好友
		 */
		onShareAppMessage(res){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/tabBar/index'
			}
		},
		/**
		 * @author smallfour
		 * @description 分享朋友圈
		 */
		onShareTimeline(){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/tabBar/index'
			}
		},
		
		methods: {
			refresh:function(){
				this.pages = 0;
				this.collextList();
			},
			controlRoll:function(){
				this.isScroll = this.isScroll ? false : true
			},
			scroll () {
				lazyLoadPlugin.scroll();
			},
			// 滚动置底
			scrolltolower(){
				this.collextList();
			},
			/**
			 * @author smallfour
			 * @description 去上传
			 */
			goUpload:function(){
				uni.navigateTo({
					url:'/pages/setting/upload'
				})
			},
			/**
			 * @author smallfour
			 * @description 我的上传列表
			 */
			uploadList:function(){
				this.pages = this.pages + 1
				let uploadObj = {
					pages:this.pages,
					sizes:20
				}
				this.$api.myUpload(uploadObj).then(res => {
					if(this.pages === 1){
						this.uploadsList = res.data ? res.data : [];
					}else{
						this.uploadsList = [... this.uploadsList , ... res.data];
					}
					lazyLoadPlugin.init({
					    id: '#scroll'
					});
				}).catch(err => {
					console.log(err);
				})
			}
		},
		components: {
		    lazyLoad
		},
		destroyed () {
		    lazyLoadPlugin.destroy();
		},
		onReachBottom(){
			this.uploadList();
		}
	}
</script>


<style lang="scss">
	.upload-btn{
		text-align: center;
		padding: 40rpx 0;
		height: 200rpx;
		button{
			width: 100rpx!important;
			height: 100rpx!important;;
			font-size: 50rpx;
		}
		view{
			margin-top: 10rpx;
			font-size: 28rpx;
		}
	}
	
	.atlas-list{
		display: flex;
		flex-wrap:wrap;
        align-items: start;
		.atlas-image{
			width:50%;
			margin-top: 30rpx;
			display: inline-block;
		}
		.atlas-image:nth-child(odd){
			padding: 0 10rpx 0 20rpx;
		}
		.atlas-image:nth-child(even){
			padding: 0 20rpx 0 10rpx;
		}
	}

    #scroll {
        height: calc(100vh - 60px - 200rpx - var(--status-bar-height));
    }
	.component-img-lazyload {
	    box-shadow: 0 2upx 12upx rgba(0, 0, 0, 0.2);
	    background: #fff;
	    min-height: 240upx;
	    border-radius: 20upx;
		line-height: 0;
	
	    /deep/ .img {
	        width: 100%;
			height: 240rpx;
	        border-radius: 14upx;
	    }
	}
</style>